var btn = document.getElementById("btn");


//封装user()
function user(){
    var acount = document.getElementsByClassName("acount")[0].value;
    if(acount == ""){               //用户名不能为空
        alert("请输入用户名！");
        return false;
    }
    return true;
}

//封装pwds()
function pwds(){
    var password = document.getElementsByClassName("password")[0].value;
    //进行判断
    if(password == ""){   
        alert("请输入密码")               //密码不能为空
        return false;
    }
    return true;
}

//添加点击事件
var btn = document.getElementById("btn");
btn.onclick = function(){
    //进行判断
    if(user()&& pwds()){
        // alert("登录成功");
        var acount = document.getElementsByClassName("acount")[0];
        var password = document.getElementsByClassName("password")[0];
        var Json = {
            userAccount:acount.value,
            userPassword:password.value
        }
        ajax.post(ajax.myUrl+"users/userLogin",Json,function(result){
            console.log(result);
            var data = result.dataset.userInfo;
            console.log(data);
            if(data == "无用户信息"){
                alert("用户名或密码不正确！");
            }else{
                localStorage.setItem("userid",data.userId);
                localStorage.setItem("username",data.userName);
                localStorage.setItem("usergender",data.userGender);
                localStorage.setItem("userphone",data.userPhone);
                localStorage.setItem("useraccount",data.userAccount);
                localStorage.setItem("userpassword",data.userPassword);
                localStorage.setItem("userrole",data.userRole);
                localStorage.setItem("userdept",data.userDept);
                location.href = "../index/index.html";
            }
            
        })

    }
}
console.log(ajax.myUrl);